/*

Author   : chaos

FileName : stl_alg_math.cpp

Date     : 17/08/17 16:22:24

*/
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int Square(int i){ return i*i; }
void print(int i){ cout << i << " "; }

int main(int argc ,char *argv[])
{
    int a[] = {1,4,7,2,9,4,3};
    vector<int> v1(a,a+7);
    int num = 0;

    cout << "Counting number of 'G' in v1 ..." << endl;
    num = count(v1.begin() ,v1.end() ,4);
    cout << "There are" << num << "number 4 in v1 . " << endl;

    cout << "Maxium element : "
        << *(max_element(v1.begin() ,v1.end())) << endl;

    cout << "Minium element : "
        << *(min_element(v1.begin() , v1.end())) << endl;

    cout << endl;

    cout << "transform element ... " << endl;
    vector<int> v2(v1.size());
    transform(v1.begin(),v1.end() ,v2.begin() ,Square);
    for_each(v2.begin(),v2.end(),print);
    cout << endl;


    return 0;
}
